/**
 * 
 */
package it.gommonauti.quiz.patente.app;

import android.annotation.TargetApi;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.ScrollView;
import android.widget.TextView;

/**
 * @author Administrator
 *
 */
public class ChooseStartIndexActivity extends BaseActivity {

	private static final String DEBUG_TAG = "LinearQuizActivity";
	
	private NumberPicker np;
	
	/* (non-Javadoc)
	 * @see it.gommonauti.quiz.patente.app.BaseActivity#onCreate(android.os.Bundle)
	 */
	@TargetApi(11)
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		String idLanguage;idLanguage = getSelectedLanguageID();
		
		int idExam = getSelectedExamID();
		
		int[] mainQuestionsIDList = getMainQuestionsIDLinear(idLanguage, idExam);
		
		//setQuizStartIndex(0);
		
		
		// TODO : ESTERNALIZZARE
		Typeface tf = Typeface.createFromAsset(getAssets(), "ASTRO867.TTF");
		
		ScrollView mainScrollView = new ScrollView(this);
		LinearLayout mainLinearLayout = new LinearLayout(this);
		mainLinearLayout.setOrientation(LinearLayout.VERTICAL);
		mainScrollView.addView(mainLinearLayout);
		this.setContentView(mainScrollView);
		
		// TODO TROVARE SOLUZIONE + ELEGANTE: MARGIN TOP...
		TextView textViewFiller = new TextView(this);
		textViewFiller.setText(System.getProperty("line.separator") + System.getProperty("line.separator"));
		mainLinearLayout.addView(textViewFiller);
		
		ImageView mainQuestionImageView = new ImageView(this);		 
		Bitmap mainQuestionImageBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo_385_65); 
		mainQuestionImageView.setImageBitmap(mainQuestionImageBitmap);
		mainLinearLayout.addView(mainQuestionImageView);
		
		TextView textView = new TextView(this);
		textView.setText(System.getProperty("line.separator") + "SCEGLIERE DA CHE DOMANDA PARTIRE" + System.getProperty("line.separator"));
		textView.setTextColor(Color.rgb(3, 96, 176));
		textView.setTypeface(tf);
		mainLinearLayout.addView(textView);

		
		np =  new NumberPicker(this);
		mainLinearLayout.addView(np);
		np.setMinValue(1);
		int maxValue = 1;
		if (mainQuestionsIDList != null) maxValue = mainQuestionsIDList.length; 
		np.setMaxValue(maxValue);
		
		 String[] displayedValues = new String[maxValue];
		    for(int i=0; i<maxValue; i++)
		    	displayedValues[i] = Integer.toString(i + 1);
		    
		np.setDisplayedValues(displayedValues);
		
		Button buttonOk = new Button(this);
		
		buttonOk.setTypeface(tf);
		buttonOk.setText("OK");
		mainLinearLayout.addView(buttonOk);
		
		buttonOk.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {

				int selectedValue = np.getValue();
				
				setQuizStartIndex(selectedValue - 1);
				
				
				// TODO: choise your quiz type:random, exam, by category, etc..
				finish();

				Intent intent = new Intent();
				intent.setClass(ChooseStartIndexActivity.this, LinearQuizActivity.class);
				startActivity(intent);			}
		});
		
	}



	@Override
	protected String getDebugTag() {
		return DEBUG_TAG;
	}

}
